<template>
	<view class="height-100 bg-or overflow-hidden">
		<!-- 患者资料 -->
		<view class="bg-white radius-xl padding margin">
			<view class="flex-direction-column">
				<text class="text-df color-green">初步诊断</text>
				<text class="text-df margin-top-sm">{{details.processAdvice}}</text>
				<text class="text-df color-green margin-top">处理意见</text>
				<text class="text-df margin-top-sm">{{details.primaryDiagnosis}}</text>
			</view>
		</view>
		<!-- 配药 -->
		<view class="bg-white radius-xl padding margin">
			<view class="padding-tb">
				<text class="text-lg color-df">配药</text>
			</view>
			<block v-for='(item,index) in details.prescriptionProductItemList' :key='index'>
				<view class="flex-direction-column padding-tb border-top">
					<view class="flex-direction-row justify-between">
						<text class="text-df text-bold">{{item.productName}}</text>
						<text class="text-sm color-black-q">x {{item.count}}</text>
					</view>
					<text class="text-smd color-black-q margin-top-xsm">规格：{{item.productSpaceName}}</text>
					<text
						class="text-smd color-black-b margin-top-xsm">{{medicationUsageArray[item.medicationUsage]}}：{{usageFrequencyArray[item.usageFrequency]}} {{unitArray[item.unit]}}</text>
				</view>
			</block>
		</view>
		<!-- 编辑处方 -->
		<view class="flex-direction-row justify-center margin-tb col-1">
			<view class="bg-df padding-lr-xl padding-tb-sm radius-sl" @click="edit">
				<text class="text-df color-white">编辑处方</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		fields
	} from "@/common/fields.js"
	export default {
		onLoad(option) {
			console.log('option: ',option);
			this.optionId = option.id
			this.getDetail();
			// 监听修改了常用处方
			uni.$on('updateSavePrescription',data=>{
				console.log('11111: ',data);
				// 获取常用处方列表
				this.getDetail();
			})
		},
		onUnload() {
			uni.$off('updateSavePrescription')
		},
		data() {
			return {
				optionId:'',
				details:{},
				usageFrequencyArray: fields.usageFrequency,
				unitArray: fields.unit,
				medicationUsageArray: fields.medicationUsage,
			}
		},
		methods: {
			async getDetail(){
				const res = await uni.$request.get('/prescriptionDoctorApi/'+this.optionId, {});
				console.log('getDetail 常用处方 res: ', res.data);
				if (res.code === 200) {
					// this.prescriptionDoctorList = res.data;
					this.details = res.data;
				} else {
					uni.showModal({
						title: '提示',
						content: '数据查询失败',
						showCancel: false
					});
				}
			},
			edit(){
				let details = {
					id:this.details.id,
					primaryDiagnosis:this.details.primaryDiagnosis,
					prescriptionProductItemList:this.details.prescriptionProductItemList,
					processAdvice:this.details.processAdvice
				}
				uni.navigateTo({
					url: '/pages/prescription/editPrescription?details='+JSON.stringify(details)
				});
			}
		}
	}
</script>

<style>

</style>
